﻿@using CommonSite.Common
@{
    Layout = "~/Views/Shared/_LayoutFrame.cshtml";
}

@section style
{
    <link type="text/css" rel="stylesheet" href="/Content/css-1.css" />
}

<div>
    <a style="margin-left:2%;font-size:medium;" href="/Work" target="_self">返回</a>
    <hr />
</div>

<div style="margin-left:2%;color:red;">
    <h3>@ViewBag.Flow["description"]</h3>
</div>

<div class="tt-content">
    <div class="tt-title">
        <h3>@ViewBag.Flow["flowname"]</h3>
    </div>
    <div class="tt-body">
        <div>
        @{
            Html.RenderPartial("~/Views/Shared/ViewTemplate.cshtml");
        }
        </div>
        <div style="margin-top:5px;">
        <form id="form1" method="post">
            <input type="hidden" id="state" name="state" value="" />
            <table class="tt-table" border="1" cellspacing="0" bordercolor="#000">
                <tr class="c1">
                    <td style="text-align:center;" colspan="2">
                        <h3>审批操作</h3>
                    </td>
                </tr>
                <tr class="c2">
                    <td style="width:20%;">审批意见:</td>
                    <td>
                        <textarea id="txtResult" name="result"></textarea>
                    </td>
                </tr>
                <tr style="height:40px;">
                    <td style="text-align:center;" colspan="2">
                        <input id="btnApprove" style="width:80px;height:30px;" type="button" value="通过" />
                        <input id="btnDeny" style="width:80px;height:30px;" type="button" value="拒绝" />
                        <input id="btnMove" style="width:80px;height:30px;" type="button" value="指派" />
                    </td>
                </tr>
            </table>
        </form>
        </div>
    </div>
</div>

<div class="tt-content">
    <div class="tt-body">
        <div id="grid">
        </div>
    </div>
    <div class="tt-foot">
        <div>
            @Html.Raw(ViewBag.Flow["flowdescription"])
        </div>
        <div style="text-align:center;margin-top:5px;">
        信诚天下、开拓未来&nbsp;&nbsp;&nbsp;&nbsp;制作部门:行政及人力资源部门
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#grid').ligerGrid({
            title: '审批历史记录',
            usePager: false,
            rownumbers: true,
            resizable: false,
            frozen: false,
            columns: [
                { name: 'taskname', display: '', width: 120 }
                , { name: 'username', display: '审批人', width: 120 }
                , {
                    name: 'state', display: '审批状态', width: 100,
                    render: function (item) {
                        switch (item.state) {
                            //0 关闭 1 初始 2 通过 3 拒绝 4 指派 5 跳过

                            case 0:
                                return '关闭';
                            case 1:
                                return '进行中';
                            case 2:
                                return '通过';
                            case 3:
                                return '拒绝';
                            case 4:
                                return '指派';
                            case 5:
                                return '跳过';
                        }
                    }
                }
                , {
                    name: 'updatedtime', display: '审批时间', width: 120
                }
                , { name: 'result', display: '审批意见', width: 300 }
            ],
            url: '/Item/WorkUsers?id=@ViewBag.Flow["id"]'
        });
    });
</script>

<div class="custom-userpicker">
    <div id="dlgUsers" style="display:none;padding:10px;">
        <div class="custom-users-query">
            部门: <input id="txtDept" type="text" />
            职位: <input id="txtPosition" type="text" />
            姓名: <input id="txtUserName" type="text" />&nbsp;
            <input style="width:45px;" value="查询" type="button" onclick="filter()" />
        </div>
        <br />
        <div class="custom-users-body">
            <div id="gridUsers">
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var gridUsers = null;
    var dlgUsers = null;

    function filter() {
        gridUsers.loadServerData({
            dept: $('#txtDept').val(),
            position: $('#txtPosition').val(),
            username: $('#txtUserName').val()
        });
    }

    $(function () {
        $('input[type=button]').click(function () {
            var k = {
                btnApprove: 1,
                btnDeny: 2,
                btnMove: 3
            };

            var v = k[this.id];
            if (v) {
                switch (v) {
                    case 1:
                    case 2:
                        $('#state').val(v);
                        $('form').submit();
                        break;

                    case 3:
                        if (gridUsers) {
                            filter();
                        } else {
                            gridUsers = $('#gridUsers').ligerGrid({
                                title: '用户信息',
                                resizable: false,
                                frozen: false,
                                height: 320,
                                enabledSort: false,
                                columns: [
                                    { name: 'UserName', display: '姓名', width: 120 }
                                    , { name: 'Org', display: '部门', width: 120 }
                                    , { name: 'Position', display: '职位', width: 120 }
                                ],
                                url: '/API/Control/GetUsers',
                                usePager: false
                            });
                        }

                        if (dlgUsers) {
                            dlgUsers.show();
                        } else {
                            dlgUsers = $.ligerDialog.open({
                                target: $('#dlgUsers'),
                                width: 600,
                                height: 480,
                                title: '指派其他人审批此申请',
                                isResize: true,
                                modal: true,
                                buttons: [
                                    {
                                        text: '确定', onclick: function () {
                                            DoAction(gridUsers, function (row) {
                                                var f = $('<form action="/Work/ChangeWorkUser" method="post">' +
                                                    '<input type="hidden" name="taskobjectid" value="@ViewBag.WorkItem["id"]" />' +
                                                    '<input type="hidden" name="userid" />' +
                                                    '<input type="hidden" name="result" />' +
                                                  '</form>');
                                                f.find('input[name=userid]').val(row.UserId);
                                                f.find('input[name=result]').val($('#txtResult').val());
                                                f.appendTo($('body'));
                                                f.submit();
                                            }, '请选择指派的目标。');
                                        }
                                    },
                                    {
                                        text: '取消', onclick: function () {
                                            dlgUsers.hide();
                                        }
                                    }
                                ]
                            });
                        }
                        break;
                }
            }
        });
    });
</script>